package com.uff.hmstpa.vision.command;

import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JComboBox;
import javax.swing.JTextField;

import com.uff.hmstpa.model.domain.Healthplan;

@SuppressWarnings("serial")
public class CreatePatientCommand extends AbstractViewCommand {
	
	JTextField cpfTextfField;
	JTextField nameTextField;
	JComboBox<Healthplan> healthPlanComboBox;
	
	public CreatePatientCommand(JTextField cpfTextfField, JTextField nameTextField, JComboBox<Healthplan> healthPlanComboBox) {
		this.cpfTextfField = cpfTextfField;
		this.nameTextField = nameTextField;
		this.healthPlanComboBox = healthPlanComboBox;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String patientName = nameTextField.getText();
		String patientCPF = cpfTextfField.getText();
		Healthplan hp = healthPlanComboBox.getItemAt(healthPlanComboBox.getSelectedIndex());

		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", patientName);
		params.put("cpf", patientCPF);
		params.put("healthplan", hp.getCode());

		controller.createPatient(params);
	}

}
